package com.zut.edu;

import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
import com.qmuiteam.qmui.widget.QMUIViewPager;
import com.qmuiteam.qmui.widget.tab.QMUITabBuilder;
import com.qmuiteam.qmui.widget.tab.QMUITabIndicator;
import com.qmuiteam.qmui.widget.tab.QMUITabSegment;
import com.zut.edu.fragment.FragmentAdapter;
import com.zut.edu.fragment.StatisticsFirstFragment;
import com.zut.edu.fragment.StatisticsSecondFragment;
import com.zut.edu.fragment.StatisticsThirdFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class StatisticsActivity  extends AppCompatActivity {

    @BindView(R.id.statistics_topbar)
    QMUITopBarLayout statisticstopbar;
    @BindView(R.id.statistics_tabs)
    QMUITabSegment mTabSegment;
    @BindView(R.id.statistics_viewpager)
    QMUIViewPager mContentViewPager;
    private ContentPage mDestPage = ContentPage.Item1;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_statistics);
        ButterKnife.bind(this);
        QMUIStatusBarHelper.translucent(this);
        initTopBar();
        initTabAndPager();

    }

    private void initTopBar() {
        statisticstopbar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        statisticstopbar.setBottomDividerAlpha(0);
        statisticstopbar.setTitle("数据统计").setGravity(Gravity.START);

    }

    private void initTabAndPager() {
        int indicatorHeight = QMUIDisplayHelper.dp2px(this, 2);
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new StatisticsFirstFragment());
        fragments.add(new StatisticsSecondFragment());
        fragments.add(new StatisticsThirdFragment());
        FragmentAdapter adapter = new FragmentAdapter(fragments, getSupportFragmentManager());
        mContentViewPager.setAdapter(adapter);
        mContentViewPager.setSwipeable(false);//取消侧滑
        mContentViewPager.setCurrentItem(mDestPage.getPosition(), false);
        QMUITabBuilder builder = mTabSegment.tabBuilder();
        mTabSegment.setIndicator(new QMUITabIndicator(indicatorHeight, false, false));
        mTabSegment.setBackgroundColor(Color.parseColor("#69615E"));
        mTabSegment.addTab(builder.setText("追溯统计").setColor(getResources().getColor(R.color.qmui_config_color_gray_6),getResources().getColor(R.color.qmui_config_color_white)).build(this));
        mTabSegment.addTab(builder.setText("审核统计").setColor(getResources().getColor(R.color.qmui_config_color_gray_6),getResources().getColor(R.color.qmui_config_color_white)).build(this));
        mTabSegment.addTab(builder.setText("结果统计").setColor(getResources().getColor(R.color.qmui_config_color_gray_6),getResources().getColor(R.color.qmui_config_color_white)).build(this));
        mTabSegment.setupWithViewPager(mContentViewPager, false);
        mTabSegment.setMode(QMUITabSegment.MODE_FIXED);
        mTabSegment.addOnTabSelectedListener(new QMUITabSegment.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int index) {
            }

            @Override
            public void onTabUnselected(int index) {

            }

            @Override
            public void onTabReselected(int index) {
            }

            @Override
            public void onDoubleTap(int index) {
                mTabSegment.clearSignCountView(index);
            }
        });
    }

    public enum ContentPage {
        Item1(0),
        Item2(1),
        Item3(2);
        public static final int SIZE = 3;
        private final int position;

        ContentPage(int pos) {
            position = pos;
        }

        public static ContentPage getPage(int position) {
            switch (position) {
                case 0:
                    return Item1;
                case 1:
                    return Item2;
                case 2:
                    return Item3;
                default:
                    return Item1;
            }
        }

        public int getPosition() {
            return position;
        }
    }


}
